package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BasePageData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wx.vo.SearchGoodsPageDataVo;
import com.cskaoyan.bean.wx.vo.WxCategoryListVo;
import com.cskaoyan.bean.wx.vo.WxDetailVo;
import com.cskaoyan.service.GoodsService;
import com.cskaoyan.utils.CommonUtil;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("wx/goods")
public class WxGoodsController {
    @Autowired
    GoodsService goodsService;

    @RequestMapping("count")
    public BaseRespVo count() {

        return BaseRespVo.ok(0 , 226 , "成功");
    }

    @RequestMapping("list")
    public BaseRespVo list(String keyword , Boolean isNew , Boolean isHot , Integer page , Integer limit , String sort , String order , Integer categoryId){
//        if (CommonUtil.isNull(keyword)) {
//            return BaseRespVo.ok();
//        }

        BasePageData basePageData = goodsService.selectGoodsCategory(keyword , isNew , isHot , page , limit , sort , order , categoryId);

        return BaseRespVo.ok(basePageData);
    }

    @RequestMapping("category")
    public BaseRespVo category(Integer id) {

        WxCategoryListVo wxCategoryListVo = goodsService.selectCategoryList(id);

        return BaseRespVo.ok(wxCategoryListVo);
    }

    @RequestMapping("detail")
    public BaseRespVo detail(HttpServletRequest req, Integer id) {

        WxDetailVo wxDetailVo = goodsService.selectWxDetail(req, id);

        return BaseRespVo.ok(wxDetailVo);
    }

    @RequestMapping("related")
    public BaseRespVo related(Integer id) {
        BasePageData basePageData = goodsService.selectWxRelated(id);

        return BaseRespVo.ok(basePageData);
    }

    /**
     * 根据关键词查询商品
     *
     * @param keyword
     * @param categoryId
     * @param param
     * @return
     */
//    @GetMapping("/list")
//    public BaseRespVo searchGoods(String keyword, Integer categoryId, BaseParam param) {
//        //如果为keyword为null则不返回数据
//        if (CommonUtil.isNull(keyword)) {
//            return BaseRespVo.ok();
//        }
//        SearchGoodsPageDataVo data = goodsService.searchGoods(keyword, categoryId, param);
//        //响应
//        return BaseRespVo.ok(data);
//    }

}
